package com.rules.admin.service.decision.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.rules.admin.dao.DecisionCellDao;
import com.rules.admin.entity.DecisionCell;
import com.rules.admin.entity.DecisionColumnConfig;
import com.rules.admin.service.decision.DecisionCellService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DecisionCellServiceImpl extends ServiceImpl<DecisionCellDao, DecisionCell> implements DecisionCellService {

   public List<DecisionCell> getCellsByRowId(long rowId) {
//      DecisionCellExample example = new DecisionCellExample();
//      Criteria criteria = example.createCriteria();
//      criteria.andRowIdEqualTo(rowId);
//      return this.selectByExample(example);

      LambdaQueryWrapper<DecisionCell> queryWrapper = new LambdaQueryWrapper<>();
      queryWrapper.eq(DecisionCell::getRowId, rowId);
      return this.baseMapper.selectList(queryWrapper);
   }

   public List<DecisionCell> geyCellsByColId(long colId) {
//   DecisionCellExample example = new DecisionCellExample();
//   Criteria criteria = example.createCriteria();
//   criteria.andColIdEqualTo(colId);
//   return this.selectByExample(example);

      LambdaQueryWrapper<DecisionCell> queryWrapper = new LambdaQueryWrapper<>();
      queryWrapper.eq(DecisionCell::getColId, colId);
      return this.baseMapper.selectList(queryWrapper);

   }

   public DecisionCell getCellByRowIdAndColId(long rowId, long colId) {
//      DecisionCellExample example = new DecisionCellExample();
//      Criteria criteria = example.createCriteria();
//      criteria.andColIdEqualTo(colId).andRowIdEqualTo(rowId);
//      return (DecisionCell)this.selectOneByExample(example);
      LambdaQueryWrapper<DecisionCell> queryWrapper = new LambdaQueryWrapper<>();
      queryWrapper.eq(DecisionCell::getRowId, rowId);
      queryWrapper.eq(DecisionCell::getColId, colId);
      return this.baseMapper.selectOne(queryWrapper);
   }

   @Override
   public void deleteByColId(long colId) {
      LambdaQueryWrapper<DecisionCell> queryWrapper= new LambdaQueryWrapper<>();
      queryWrapper.ge(DecisionCell::getColId,colId);
      this.baseMapper.delete(queryWrapper);
   }
}
